﻿Public Class FormKineticMeasurement1
    Private WithEvents UcDigitalKeyboard1 As ucDigitalKeyboard
    Private objLxjcInfo As New clsLxjcInfo
    Private objProdInfo As New clsProdInfo
    Private objProdSpec As New clsProdSpec
    Private objLhPgd As New clsLhPgd
    Private en1 As entity_lxjcInfo1
    Public usr As String
    Private Sub FormKineticMeasurement1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        dtDate.Text = Now()
        txtBarCode.Select()
    End Sub

    Private Sub search()
        '查询力学检测信息
        Dim dtLxjcTable As DataTable = objLxjcInfo.SelectByProdId(txtBarCode.Text.Trim())
        If dtLxjcTable.Rows.Count = 0 Then
            MsgBox("该标签号未入库，请先入库", vbYes, "提示")
        End If
        If dtLxjcTable.Rows.Count = 1 Then
            If DBNull.Value.Equals(dtLxjcTable.Rows(0)("status")) Then
                Label1.Text = dtLxjcTable.Rows(0)("b_pgd_mes_sys_id")
                '查询硫化信息
                Dim dttable As DataTable = objProdInfo.getProdInfoById(txtBarCode.Text.Trim(), "12")
                If dttable.Rows.Count > 0 Then
                    txt_initial_spec.Text = dttable.Rows(0)("prod_spec_id")
                    txt_plate_number.Text = dttable.Rows(0)("lhj_id")
                    If dttable.Rows(0)("flb_up_no").Equals(DBNull.Value) Then
                        txt_up_flb_number.Text = String.Empty
                    Else
                        txt_up_flb_number.Text = dttable.Rows(0)("flb_up_no")
                    End If
                    If dttable.Rows(0)("flb_down_no").Equals(DBNull.Value) Then
                        txt_down_flb_number.Text = String.Empty
                    Else
                        txt_down_flb_number.Text = dttable.Rows(0)("flb_down_no")
                    End If
                    txt_steel_seal_no.Text = dttable.Rows(0)("steel_seal_no")
                    txt_jl_type.Text = dttable.Rows(0)("jp_type")
                    txt_mould_number.Text = dttable.Rows(0)("mould_no")
                    If String.IsNullOrEmpty(txt_initial_spec.Text.Trim()) = False Then
                        Dim dtt As DataTable = objProdSpec.getProdSpecInfo(txt_initial_spec.Text.Trim())
                        If dtt.Rows.Count > 0 Then
                            txt_model1.Text = dtt.Rows(0)("prod_spec_name")
                            txt_xj_height_total.Value = dtt.Rows(0)("xj_height_total")
                        End If
                    End If
                    If String.IsNullOrEmpty(dttable.Rows(0)("b_pgd_lh_details_sys_id")) = False Then
                        Dim dtlh As DataTable = objLhPgd.getListBySysId(dttable.Rows(0)("b_pgd_lh_details_sys_id"))
                        txt_Name.Text = dtlh.Rows(0)("mes_project_name")
                    End If
                Else
                    MsgBox("该生产编号不在力学仓库无法进行力学检测！", vbYes, "提示")
                End If
            Else

            End If
        Else

        End If
    End Sub

    Private Sub txt_scbh_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtBarCode.KeyPress
        If String.IsNullOrEmpty(txtBarCode.Text.Trim()) = False Then
            If e.KeyChar = vbCr Then
                search()
            End If
        End If
    End Sub

    Private Sub clearForm1()
        For Each obj As Object In Me.Controls
            If obj.GetType.ToString = "DevExpress.XtraEditors.TextEdit" Or
               obj.GetType.ToString = "System.Windows.Forms.ComboBox" Or
               obj.GetType.ToString = "DevExpress.XtraEditors.MemoEdit" Then
                obj.text = String.Empty
            End If
            If obj.GetType.ToString = "DevExpress.XtraEditors.SpinEdit" Then
                obj.text = "0"
            End If
        Next
        dtDate.Text = Now()
    End Sub

    Private Sub setEntity1(sysId As String)
        en1 = New entity_lxjcInfo1
        With en1
            .sys_id = sysId
            .factory_id = g_factory_id
            .prod_id = txtBarCode.Text.Trim()
            .project_name = txt_Name.Text.Trim()
            .control_area = cmb_control_area.Text.Trim()
            .initial_spec = txt_initial_spec.Text.Trim()
            .final_spec = cmb_final_spec.Text.Trim()
            .model = txt_model1.Text.Trim()
            .jl_type = txt_jl_type.Text
            .experimental_pressure_vlaue = txt_experimental_pressure_vlaue.Value
            .support_model_all_count = txt_support_model_all_count.Value
            .support_model_no = txt_support_model_no.Value
            .check_date = dtDate.Text

            .plane_dimension = txt_plane_dimension.Text.Trim()
            .diameter_mesopore = txt_diameter_mesopore.Text.Trim()
            .perpendicularity_side_surface = txt_perpendicularity_side_surface.Value
            .support_model_height = txt_support_model_height.Text.Trim()
            .support_model_smooth = txt_support_model_smooth.Value
            .lateral_deformation = txt_lateral_deformation.Value
            .residual_after_detection = txt_residual_after_detection.Value
            .horizontal_offset_Measured_value = txthorizontal_offset_Measured_value.Text.Trim()
            .horizontal_offset_Maximum = txthorizontal_offset_Maximum.Value

            .total_thickness_rubber_layer = txt_xj_height_total.Value

            .experimental_temperature = txt_experimental_temperature.Value

            '铅芯

            .lead_core_height = txt_lead_core_height.Text.Trim()
            .lead_core_weight = txt_lead_core_weight.Text.Trim()
            .lead_core_factory = txt_lead_core_factory.Text.Trim()
            .lead_free_conversion = txt_lead_free_conversion.Text.Trim()
            .judgment_basis = txt_judgment_basis.Text.Trim()
            .detection_judgment = txt_detection_judgment.Text.Trim()

            '其他
            .mould_number = txt_mould_number.Text.Trim()
            .plate_number = txt_plate_number.Text.Trim()
            .up_flb_number = txt_up_flb_number.Text.Trim()
            .down_flb_number = txt_down_flb_number.Text.Trim()

            .check_address = txt_check_address.Text.Trim()
            .check_bz = txt_check_bz.Text.Trim()
            .note = tm_note.Text.Trim()
            .ope = usr
            .b_pgd_mes_sys_id = Label1.Text
            .update_time = Now()
        End With

    End Sub

    Private Sub btnSave_Click(sender As Object, e As EventArgs) Handles btnSave.Click
        If chkEmpty(txtBarCode) = False Then Exit Sub
        If chkEmpty(txt_Name) = False Then Exit Sub
        If chkEmpty(cmb_control_area) = False Then Exit Sub
        If chkEmpty(txt_initial_spec) = False Then Exit Sub
        If chkEmpty(cmb_final_spec) = False Then Exit Sub
        If chkEmpty(txt_model1) = False Then Exit Sub
        If chkEmpty(txt_jl_type) = False Then Exit Sub

        If chkZero(txt_experimental_pressure_vlaue) = False Or chkNegative(txt_experimental_pressure_vlaue) = False Then
            Exit Sub
        End If
        If chkZero(txt_support_model_all_count) = False Or chkNegative(txt_support_model_all_count) = False Then
            Exit Sub
        End If
        If chkZero(txt_support_model_no) = False Or chkNegative(txt_support_model_no) = False Then
            Exit Sub
        End If
        If chkEmpty(dtDate) = False Then Exit Sub

        If chkEmpty(txt_plane_dimension) = False Then
            Exit Sub
        End If

        'If chkZero(txt_diameter_mesopore) = False Or chkNegative(txt_diameter_mesopore) = False Then
        '    Exit Sub
        'End If

        If chkZero(txt_perpendicularity_side_surface) = False Or chkNegative(txt_perpendicularity_side_surface) = False Then
            Exit Sub
        End If

        If chkEmpty(txt_support_model_height) = False Then
            Exit Sub
        End If
        If chkZero(txt_support_model_smooth) = False Or chkNegative(txt_support_model_smooth) = False Then
            Exit Sub
        End If
        If chkZero(txt_lateral_deformation) = False Or chkNegative(txt_lateral_deformation) = False Then
            Exit Sub
        End If

        If chkZero(txt_residual_after_detection) = False Or chkNegative(txt_residual_after_detection) = False Then
            Exit Sub
        End If
        If chkEmpty(txthorizontal_offset_Measured_value) = False Then
            Exit Sub
        End If
        If chkZero(txthorizontal_offset_Maximum) = False Or chkNegative(txthorizontal_offset_Maximum) = False Then
            Exit Sub
        End If
        'If chkZero(txt_vertical_stiffness_standard) = False Or chkNegative(txt_vertical_stiffness_standard) = False Then
        '    Exit Sub
        'End If
        'If chkZero(txt_yield_force_standard) = False Or chkNegative(txt_yield_force_standard) = False Then
        '    Exit Sub
        'End If
        'If chkZero(txt_post_yield_stiffness_standard) = False Or chkNegative(txt_post_yield_stiffness_standard) = False Then
        '    Exit Sub
        'End If
        'If chkZero(txt_equivalent_stiffness_standard) = False Or chkNegative(txt_equivalent_stiffness_standard) = False Then
        '    Exit Sub
        'End If

        'If chkZero(txt_equivalent_damping_ratio_standard) = False Or chkNegative(txt_equivalent_damping_ratio_standard) = False Then
        '    Exit Sub
        'End If
        'If chkEmpty(txt_design_area) = False Then Exit Sub
        'If chkZero(txt_vertical_stiffness_result) = False Or chkNegative(txt_vertical_stiffness_result) = False Then
        '    Exit Sub
        'End If
        'If chkZero(txt_yield_force_result) = False Or chkNegative(txt_yield_force_result) = False Then
        '    Exit Sub
        'End If
        'If chkZero(txt_post_yield_stiffness_result) = False Or chkNegative(txt_post_yield_stiffness_result) = False Then
        '    Exit Sub
        'End If
        'If chkZero(txt_equivalent_stiffness_result) = False Or chkNegative(txt_equivalent_stiffness_result) = False Then
        '    Exit Sub
        'End If
        'If chkZero(txt_equivalent_damping_ratio_result) = False Or chkNegative(txt_equivalent_damping_ratio_result) = False Then
        '    Exit Sub
        'End If
        If chkZero(txt_xj_height_total) = False Or chkNegative(txt_xj_height_total) = False Then
            Exit Sub
        End If
        If chkZero(txt_experimental_temperature) = False Or chkNegative(txt_experimental_temperature) = False Then
            Exit Sub
        End If
        'If chkEmpty(txt_judgment_mechanical_properties) = False Then Exit Sub

        'If chkZero(txt_lead_core_height) = False Or chkNegative(txt_lead_core_height) = False Then
        '    Exit Sub
        'End If

        'If chkZero(txt_lead_core_weight) = False Or chkNegative(txt_lead_core_weight) = False Then
        '    Exit Sub
        'End If
        'If chkEmpty(txt_lead_core_factory) = False Then Exit Sub
        'If chkEmpty(txt_lead_free_conversion) = False Then Exit Sub

        'If chkEmpty(txt_judgment_basis) = False Then Exit Sub

        If chkEmpty(txt_detection_judgment) = False Then Exit Sub

        'If chkEmpty(txt_warehousing_area) = False Then Exit Sub

        If chkEmpty(txt_mould_number) = False Then Exit Sub

        If chkEmpty(txt_plate_number) = False Then Exit Sub

        If chkEmpty(txt_up_flb_number) = False Then Exit Sub

        If chkEmpty(txt_down_flb_number) = False Then Exit Sub

        If chkEmpty(txt_check_address) = False Then Exit Sub

        If chkEmpty(txt_check_bz) = False Then Exit Sub

        Dim dtx As DataTable = objProdInfo.getProdInfoById(txtBarCode.Text.Trim(), "12")

        If dtx.Rows.Count = 0 Then
            MsgBox("该生产编号不在力学仓库无法进行力学检测！", vbYes, "提示")
            Exit Sub
        End If

        Dim dtLxjcTable As DataTable = objLxjcInfo.SelectByProdId(txtBarCode.Text.Trim())
        setEntity1(dtLxjcTable.Rows(0)("sys_id"))
        If DBNull.Value.Equals(dtLxjcTable.Rows(0)("status")) Then
            If objLxjcInfo.update1(en1) <> -2 Then
                MsgBox("保存成功", vbYes, "提示")
                clearForm1()
            Else
                MsgBox("保存失败", vbYes, "提示")
            End If
        End If

    End Sub


    Private Sub txt_support_model_height_EditValueChanged(sender As Object, e As EventArgs) Handles txt_support_model_height.EditValueChanged
        If String.IsNullOrEmpty(txt_support_model_height.Text.Trim()) = False Then
            If txt_support_model_height.Text.Contains("-") Then
                Dim support_model_height_list As String() = txt_support_model_height.Text.Trim().Split("-")
                If support_model_height_list.Count() = 6 Then
                    Dim max_abs0 = Math.Max(
                                Math.Abs(support_model_height_list(0) - support_model_height_list(3)),
                                Math.Abs(support_model_height_list(1) - support_model_height_list(4)))
                    Dim max_abs1 = Math.Max(Math.Abs(max_abs0),
                        Math.Abs(support_model_height_list(2) - support_model_height_list(5)))
                    txt_support_model_smooth.Value = FormatNumber(max_abs1, 2, vbTrue)
                End If
            End If
        End If
    End Sub

    Private Sub txthorizontal_offset_Measured_value_EditValueChanged(sender As Object, e As EventArgs) Handles txthorizontal_offset_Measured_value.EditValueChanged
        If String.IsNullOrEmpty(txthorizontal_offset_Measured_value.Text.Trim()) = False Then
            If txthorizontal_offset_Measured_value.Text.Contains("-") Then
                Dim horizontal_offset_Measured_value_list As String() = txthorizontal_offset_Measured_value.Text.Trim().Split("-")
                If horizontal_offset_Measured_value_list.Count() = 6 Then
                    Dim max_ = horizontal_offset_Measured_value_list.Max()
                    txthorizontal_offset_Maximum.Value = FormatNumber(max_, 2, vbTrue)
                End If
            End If
        End If
    End Sub


    Private Sub txt_MouseDown(sender As Object, e As MouseEventArgs) Handles txt_xj_height_total.MouseDown, txt_support_model_smooth.MouseDown,
        txt_support_model_no.MouseDown, txt_support_model_all_count.MouseDown, txt_residual_after_detection.MouseDown,
        txt_perpendicularity_side_surface.MouseDown, txt_lead_core_weight.MouseDown,
        txt_lead_core_height.MouseDown, txt_lateral_deformation.MouseDown, txt_experimental_temperature.MouseDown,
        txt_experimental_pressure_vlaue.MouseDown, txt_diameter_mesopore.MouseDown,
        txthorizontal_offset_Maximum.MouseDown, txt_plane_dimension.MouseDown,
        txt_support_model_height.MouseDown, txthorizontal_offset_Measured_value.MouseDown
        UcDigitalKeyboard1 = New ucDigitalKeyboard
        If sender.MaskBox.Mask.EditMask = "d" Then
            UcDigitalKeyboard1.B_01 = False
        Else
            UcDigitalKeyboard1.B_01 = True
        End If

        If sender.GetType().Name.Equals("TextEdit") Then
            UcDigitalKeyboard1.B_02 = True
        Else
            UcDigitalKeyboard1.B_02 = False
        End If

        UcDigitalKeyboard1.Txt = sender

        Me.Controls.Add(UcDigitalKeyboard1)
        UcDigitalKeyboard1.Show()
        UcDigitalKeyboard1.BringToFront()
        UcDigitalKeyboard1.Focus()

    End Sub

    Private Sub ucdigitalkeyboard1_leave(sender As Object, e As EventArgs) Handles UcDigitalKeyboard1.Leave
        UcDigitalKeyboard1.Dispose()
    End Sub


End Class


Public Class entity_lxjcInfo1
    Public sys_id As String
    Public factory_id As String
    '支座信息
    Public prod_id As String
    Public project_name As String
    Public control_area As String
    Public initial_spec As String
    Public final_spec As String
    Public model As String
    Public jl_type As String
    Public experimental_pressure_vlaue As String
    Public support_model_all_count As String
    Public support_model_no As String
    Public check_date As String

    Public total_thickness_rubber_layer As String
    Public experimental_temperature As String
    '外观
    Public plane_dimension As String '平面尺寸
    Public diameter_mesopore As String '中孔直径
    Public perpendicularity_side_surface As String '侧表面垂直度
    Public support_model_height As String '支座高度
    Public support_model_smooth As String '支座平整度
    Public lateral_deformation As String '侧向变形量
    Public residual_after_detection As String '检测后残变
    Public horizontal_offset_Measured_value As String '水平偏移
    Public horizontal_offset_Maximum As String '最大偏移

    '铅芯

    Public lead_core_height As String '铅芯高度
    Public lead_core_weight As String '铅芯重量
    Public lead_core_factory As String '铅芯厂家
    Public lead_free_conversion As String '有铅无铅转换
    Public judgment_basis As String '判定依据
    Public detection_judgment As String '检测判定

    '其他
    Public mould_number As String '模具编号
    Public plate_number As String '平板编号
    Public up_flb_number As String '上法兰板编号
    Public down_flb_number As String '下法兰板编号

    Public check_address As String '检测地点
    Public check_bz As String '检验班组
    Public note As String '备注

    Public ope As String
    Public b_pgd_mes_sys_id As String
    Public update_time As String
End Class